package com.example.daotingli2025_3_17;

import static com.example.daotingli2025_3_17.R.id.femaleRadioButton;
import static com.example.daotingli2025_3_17.R.id.maleRadioButton;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {
    private String sex="男";
    private String[] hop = {"","",""};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        Button long_in_btn= findViewById(R.id.submitButton);
        RadioGroup radioGroup = findViewById(R.id.genderRadioGroup);// 性别单选按钮组
        RadioButton maleRadioButton = findViewById(R.id.maleRadioButton);// 男单选按钮
        RadioButton femaleRadioButton = findViewById(R.id.femaleRadioButton);// 女单选按钮
        CheckBox checkBox = findViewById(R.id.singingCheckBox);// 唱歌
        CheckBox checkBox1 = findViewById(R.id.dancingCheckBox);// 跳舞
        CheckBox checkBox2 = findViewById(R.id.footballCheckBox);// 足球
        EditText nameText= findViewById(R.id.nameEditText); //姓名输入框
        EditText passwordText= findViewById(R.id.passwordEditText); // 密码输入框
        EditText emailText= findViewById(R.id.emailEditText);// 邮箱输入框

        checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> {
            if (isChecked) {
                hop[0] ="唱歌";
            } else {
                hop[0]=" ";
            }

        });
        checkBox1.setOnCheckedChangeListener((buttonView1, isChecked1) -> {
            if (isChecked1) {
                hop[1]="跳舞";
            } else {
                hop[1]=" ";
            }
        });
        checkBox2.setOnCheckedChangeListener((buttonView2, isChecked2) -> {
            if (isChecked2) {
                hop[2]="足球";
            } else {
                hop[2]=" ";
            }
        });
        long_in_btn.setOnClickListener(v -> {
            String name = nameText.getText().toString();
            String password = passwordText.getText().toString();
            String email = emailText.getText().toString();
            if (name.isEmpty() || password.isEmpty() || email.isEmpty()) {
                TextView errorTextView = findViewById(R.id.wechatRegisterTextView);
                errorTextView.setText("请填写完整信息");
                errorTextView.setVisibility(TextView.VISIBLE);
            } else {
                TextView errorTextView = findViewById(R.id.wechatRegisterTextView);
                errorTextView.setVisibility(TextView.GONE);
                // 处理登录逻辑
            }
            radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @SuppressLint("NonConstantResourceId")
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                   if(checkedId==maleRadioButton.getId()){
                       sex="男";
                   }else if(checkedId==femaleRadioButton.getId()){
                       sex="女";
                   }
                }
            });

            // 弹出所有信息// 上面已经获取到的
            System.out.println("姓名：" + name);
            System.out.println("密码：" + password);
            System.out.println("邮箱：" + email);
            System.out.println("性别：" + sex);
            System.out.println("兴趣爱好：" + hop[0]+hop[1]+hop[2]);
            Log.d("we" , "name:"+name);
            Log.d("we" , "密码："+password);
            Log.d("we" , "邮箱："+email);
            Log.d("we" , "性别："+sex);
            Log.d("we" , "兴趣爱好："+hop[0]+hop[1]+hop[2]);

            System.out.println("--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
            Toast.makeText(this, "姓名：" + name + "\n密码：" + password + "\n邮箱：" + email + "\n性别：" + sex + "\n兴趣爱好：" + hop[0]+hop[1]+hop[2], Toast.LENGTH_LONG).show();
        });


    }
}